#include "prey.h"
#include "environment.h"
#include <stdlib.h>

Prey::Prey(Environment * newEnv) : Animal(newEnv) {}

// Function that returns the action chosen by the prey
int Prey::move() {
	// Prey decides his own move
	if ( ( rand() % 100  ) < 80 )
		// We stand still
		return 4;
	else {
		// Prey observes environment
		int predPos = ownEnv->isPredatorNearby(this);

		if ( predPos != -1  )
			// Predator is nearby, don't go in that direction
			return ( ( rand() % 3 + 1 ) + predPos ) % 4 ;
		else
			// We are alone
			return ( rand() % 4 );
	}
}
